package lzyc.pointsManagement.business.activity.convertor;

import lzyc.pointsManagement.business.activity.domain.ActivityInfo;
import lzyc.pointsManagement.business.activity.dto.ActivityInfoDto;
import lzyc.pointsManagement.common.utils.StringUtils;
import lzyc.pointsManagement.common.utils.uuid.IdUtils;

import java.util.Date;

public class ActivityInfoConvertor {

    public static ActivityInfoDto convertToDto(ActivityInfo entity) {
        ActivityInfoDto activityInfoDto = new ActivityInfoDto();
        if (entity != null) {
            activityInfoDto.setId(entity.getId());
            activityInfoDto.setCode(entity.getCode());
            activityInfoDto.setName(entity.getName());
            activityInfoDto.setDescription(entity.getDescription());
            activityInfoDto.setCreateTime(entity.getCreateTime());
            activityInfoDto.setEndTime(entity.getEndTime());
            activityInfoDto.setScore(entity.getScore());
        }
        return activityInfoDto;
    }

    public static ActivityInfo convertToEntity(ActivityInfoDto dto) {
        ActivityInfo activityInfo = new ActivityInfo();
        if (dto != null) {
            if (StringUtils.isEmpty(dto.getId())) {
                activityInfo.setId(IdUtils.randomUUID());
                dto.setId(activityInfo.getId());
            } else {
                activityInfo.setId(dto.getId());
            }
            activityInfo.setCode(dto.getCode());
            activityInfo.setName(dto.getName());
            activityInfo.setDescription(dto.getDescription());
            if (dto.getCreateTime() == null) {
                activityInfo.setCreateTime(new Date());
                dto.setCreateTime(activityInfo.getCreateTime());
            } else {
                activityInfo.setCreateTime(dto.getCreateTime());
            }
            activityInfo.setEndTime(dto.getEndTime());
            activityInfo.setScore(dto.getScore());
        }
        return activityInfo;
    }
}
